package com.activiti6.demo.controller;

import com.activiti6.demo.vo.UserVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@Controller
public class LoginController {



    @PostMapping("/login")
    @ResponseBody
    public boolean login(HttpSession session, @RequestBody UserVo user) {
        String userName = user.getUserName();
        String password = user.getPassword();
        session.setAttribute("userName", userName);
        return true;
    }


    @PostMapping("/test")
    @ResponseBody
    public boolean test(@RequestBody Map<String,Object> map) {
//        UserVo[] userVos = (UserVo[]) map.get("users");
        List<UserVo> userVos1 = (List<UserVo>) map.get("users");
        System.out.println("======");
        return true;
    }




    @GetMapping("/exit")
    public void exit(HttpSession session, HttpServletResponse response) throws IOException {
        session.removeAttribute("userName");
        response.sendRedirect("/");
    }




}
